package com.example.smartcity_poverty.ui.AllService.OA.activity

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.ui.AllService.OA.activity.OaShowMeActivity.Companion.OaName
import com.example.smartcity_poverty.ui.AllService.OA.fragment.OaShowMeAoDataFragment
import com.example.smartcity_poverty.ui.AllService.OA.fragment.OaShowMeAoDataFragment.Companion.OaIdAAA
import com.example.smartcity_poverty.ui.AllService.OA.fragment.OaShowMeAoDataFragment.Companion.OaShowMeId
import com.example.smartcity_poverty.ui.AllService.OA.fragment.OaShowMeAoDataFragment.Companion.oaShowName
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.activity_oa_show_me_ao.*

/**
 *  科室
 */
class OaShowMeAoActivity : AppCompatActivity() {

    private val id by lazy { intent.getStringExtra("id")?.toInt() }
    private val name by lazy { intent.getStringExtra("name") }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_oa_show_me_ao)
        title = "科室"

        val tab = oaShowMeAoTabLayout
        val vp = oaShowMeAoViewPager2

        vp.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int = 2

            override fun createFragment(position: Int): Fragment = when (position) {
                0 -> OaShowMeAoDataFragment()
                else -> OaShowMeAoDataFragment()
            }

            override fun getItemId(position: Int): Long {
                OaIdAAA = id!!
                oaShowName = name.toString()
                OaShowMeId = when (position) {
                    0 -> 10
                    else -> 20
                }
                return super.getItemId(position)
            }
        }


        TabLayoutMediator(tab, vp) { tab, position ->
            when (position) {
                0 -> tab.text = "普通"
                else -> tab.text = "专家"
            }
        }.attach()

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}